/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author submonkey
 */
public abstract class AbstractDao {

    public HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Transactional(readOnly=false)
    public void save(Object object) {
        hibernateTemplate.saveOrUpdate(object);
    }

    @Transactional(readOnly=false)
    public void update(Object object) {
        hibernateTemplate.update(object);
    }

    @Transactional(readOnly=false)
    public void delete(Object object) {
        hibernateTemplate.delete(object);
    }

    public abstract List<?> getAll(String query);

    public abstract List<?> getAllByDate(String start, String end);
    
    public abstract List<?> getById(Long id);
    
    public abstract List<?> getAllByMonth(String month);
    
    public List custom(String query) {
        return hibernateTemplate.find(query);
    }
    
    public abstract double getMax();
    
    public abstract double getMin();
}
